package com.wolfheader.wolfgame.entity.admin;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.OneToMany;
import javax.persistence.PrePersist;
import javax.persistence.Table;

import com.wolfheader.wolfgame.entity.BaseEntity;

@Entity
@Table(name = "t_product")
public class ProductEntity extends BaseEntity {

	/**
	 * 
	 */
	private static final long serialVersionUID = -5509613682221383840L;

	/**
	 * 产品名称
	 */
	private String name;

	/**
	 * 产品备注
	 */
	private String remark;

	/**
	 * 产品代理
	 */
	private Set<PersonEntity> persons = new HashSet<PersonEntity>();

	/**
	 * 产品级别
	 */
	private Set<ProductLevelEntity> levels = new HashSet<ProductLevelEntity>();

	/**
	 * 箱转盒单位
	 */
	private Integer xiangUnit;

	/**
	 * 盒转片单位
	 */
	private Integer heUnit;

	/**
	 * 是否启用
	 */
	private Boolean enabled;

	@Column(nullable = false)
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getRemark() {
		return remark;
	}

	public void setRemark(String remark) {
		this.remark = remark;
	}

	@OneToMany(mappedBy = "product", fetch = FetchType.LAZY)
	public Set<PersonEntity> getPersons() {
		return persons;
	}

	public void setPersons(Set<PersonEntity> persons) {
		this.persons = persons;
	}

	@OneToMany(mappedBy = "product", fetch = FetchType.LAZY, cascade = CascadeType.REMOVE)
	public Set<ProductLevelEntity> getLevels() {
		return levels;
	}

	public void setLevels(Set<ProductLevelEntity> levels) {
		this.levels = levels;
	}

	@Column(nullable = false)
	public Integer getXiangUnit() {
		return xiangUnit;
	}

	public void setXiangUnit(Integer xiangUnit) {
		this.xiangUnit = xiangUnit;
	}

	@Column(nullable = false)
	public Integer getHeUnit() {
		return heUnit;
	}

	public void setHeUnit(Integer heUnit) {
		this.heUnit = heUnit;
	}

	public Boolean getEnabled() {
		return enabled;
	}

	public void setEnabled(Boolean enabled) {
		this.enabled = enabled;
	}

	@PrePersist
	public void prePersist() {
		if (getEnabled() == null) {
			setEnabled(true);
		}
		if (getHeUnit() == null) {
			setHeUnit(0);
		}
		if (getXiangUnit() == null) {
			setXiangUnit(0);
		}
	}
}
